import Vue from 'vue'
import Vuex from 'vuex'
import createPersistedState from "vuex-persistedstate"
Vue.use(Vuex)

export default new Vuex.Store({
    state: {
        list: [
            {
                text: "new 1",
                select: false
            },
            {
                text: "new 2",
                select: true
            },
            {
                text: "new 3",
                select: false
            },
            {
                text: "new 4",
                select: false
            }
        ]
    },
    mutations: {
        addItem(state, str) {
            state.list.push({
                text: str,
                select: false
            })
        },
        deleteItem(state, index) {
            state.list.splice(index, 1)
        },
        checkAllItem(state, select){
            state.list.forEach(item=>{
                item.select = select;
            })
        },
        deleteAllCheck(state){
            state.list = state.list.filter(i => !i.select)
        }
    },
    actions: {},
    getters: {
        listLength(state) {
            return state.list.length
        },
        getChecksLength(state) {
            return state.list.filter(i => i.select).length
        }
    },
    modules: {},
    plugins: [//插件
        createPersistedState()
    ]
})
